/*
环形缓存使用步骤：
1.为环形缓存开辟静态数组(全局变量)；
2.实例化T_ringbuf对象；
3.初始化T_ringbuf对象；
4.调用api函数进行put\puts\get\gets等操作

#define UART_RXBUF_LEN    128
#define UART_TXBUF_LEN    512
static T_ringbuf rb_rx;
static T_ringbuf rb_tx;
static uint8_t comBuf_rx[UART_RXBUF_LEN];
static uint8_t comBuf_tx[UART_TXBUF_LEN];

void main()
{
	uint16_t len;

	uint8_t s_buf[UART_RXBUF_LEN];

	api_ringbuf_init(&rb_rx,comBuf_rx,UART_RXBUF_LEN);
	api_ringbuf_init(&rb_tx,comBuf_tx,UART_TXBUF_LEN);	

	while(1)
	{
		delay(100);
		len = api_ringbuf_gets(&rb_rx,s_buf,UART_RXBUF_LEN);
		if(len != 0)
		{
			api_ringbuf_puts(&rb_tx,s_buf,len);
		}
	}
}
*/
#ifndef _RINGBUF_H
#define _RINGBUF_H

#include <stdio.h>
#include <stdint.h>

#define RB_TRUE     1
#define RB_FALSE    0

typedef struct{
	uint8_t *ptr;           //缓存地址
	uint16_t size;          //缓存大小

	uint16_t pW;            //写指针
	uint16_t pR;            //读指针
	uint16_t cnt;           //环形缓存中可读数据数

    uint32_t w_total;       //写入到环形缓存的总字节数
    uint32_t r_total;       //从环形缓存中读的总字节数
}T_ringbuf;

uint8_t api_ringbuf_isEmpty(T_ringbuf *p);
uint8_t api_ringbuf_isFull(T_ringbuf *p);
uint16_t api_ringbuf_get_cnt(T_ringbuf *p);
uint8_t api_ringbuf_put(T_ringbuf *p,uint8_t byte);
uint8_t api_ringbuf_init(T_ringbuf *p,uint8_t *ptr,uint16_t size);
uint16_t api_ringbuf_getChar(T_ringbuf *p,uint8_t *pDes);
uint16_t api_ringbuf_gets(T_ringbuf *p,uint8_t *pDes,uint16_t len);



#endif